﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Composite.Events;
using AMail.Common.Events;
using AMail.Common.Interfaces.Data;
using Microsoft.Practices.Unity;
using AMail.Modules.Messages.Models;
using AMail.Modules.Messages.ViewModels;
using AMail.Modules.Messages.Views;
using AMail.Common;

namespace AMail.Modules.Messages
{
  public class MessagesModule : IModule
  {
    private IRegionManager regionManager;
    private IUnityContainer container;

    public MessagesModule(IUnityContainer container, IRegionManager regionManager, IEventAggregator eventAggregator)
    {
      this.regionManager = regionManager;
      this.container = container;

      container.RegisterType<IMessageListViewModel, MessageListViewModel>();
      container.RegisterType<IMessageViewModel, MessageViewModel>();
    }

    #region IModule Members

    public void Initialize()
    {
      var listView = this.container.Resolve<MessageListView>();
      this.regionManager.AddToRegion(RegionNames.List, listView);

      var messageView = this.container.Resolve<MessageView>();
      this.regionManager.AddToRegion(RegionNames.Viewer, messageView);
    }

    #endregion
  }
}
